/**
 * Created by dell on 2018/12/11.
 */
/*
后台接口开发
 */

const express = require('express');
const db = require('./db.js');
const app = express();
//启动路由器   指定api的路径allBook
//jsonp接口
app.get('/allBook',(req,res)=>{
    let sql = 'select * from book';
    db.base(sql,null,(result)=>{
        //在网页浏览时  http://localhost:3000/allBook?callback=fo   fo是任意的
        res.jsonp(result);
    });
});
//json接口
// app.get('/allBook',(req,res)=>{
//     let sql = 'select * from book';
//     db.base(sql,null,(result)=>{
//         res.json(result);
//     });
// });
//监听窗口
app.listen(3000,()=>{
   console.log('running....');
});